
import os

dir = r"G:\samples\face\train_aug_120x120\train_aug_120x120"
imgs_path = os.listdir(dir)
cls_list = []
idx = 0
file = open("label.txt", "w")
for img_path in imgs_path:
    s_path = img_path.split("_")
    cls_name = ""
    name_len = 0
    if "HELENFlip" == s_path[0]:
        name_len = 3
    elif "IBUGFlip" == s_path[0] or "IBUG" == s_path[0]:
        name_len = 4
    elif "LFPWFlip" == s_path[0] or "LFPW" == s_path[0]:
        name_len = 5

    for i in range(0,name_len):
        cls_name += s_path[i] + "_"
    if cls_name not in cls_list:
        cls_list.append(cls_name)
        idx = len(cls_list) - 1
    else:
        idx = cls_list.index(cls_name)
    print("%s,%d\n"%(img_path,idx))
    file.write("%s,%d\n"%(img_path,idx))
    # file.write("%s,%d,%s\n"%(img_path,idx,cls_name))
    file.flush()
file.close()






